package smartrpc.boot.starter.service;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.AnnotationMetadata;

/**
 * Created By gao_e on 2020/3/8 13:26
 * 暂时不用
 */
@Deprecated
public class SmartRPCImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar,
        EnvironmentAware, BeanFactoryAware, BeanClassLoaderAware, ResourceLoaderAware {

    private ClassLoader classLoader;
    private BeanFactory beanFactory;
    private Environment environment;
    private ResourceLoader resourceLoader;

    @Override
    public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry beanDefinitionRegistry) {
        System.out.println("这里可以让spring管理我们自己定义的注解标识的类实例");
        //扫描注解
//        Map<String, Object> annotationAttributes = annotationMetadata
//                .getAnnotationAttributes(ComponentScan.class.getName());
//        String[] basePackages = (String[]) annotationAttributes.get("basePackages");
//
//        //扫描类
//        ClassPathBeanDefinitionScanner scanner =
//                new ClassPathBeanDefinitionScanner(beanDefinitionRegistry, false);
//        TypeFilter helloServiceFilter = new AssignableTypeFilter(SmartRPCService.class);
//
//        scanner.addIncludeFilter(helloServiceFilter);
//        scanner.scan(basePackages);
    }

    @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
        this.classLoader = classLoader;
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;
    }

    @Override
    public void setEnvironment(Environment environment) {
        this.environment = environment;
    }

    @Override
    public void setResourceLoader(ResourceLoader resourceLoader) {
        this.resourceLoader = resourceLoader;
    }
}
